/*
 * Reflexis is Copyright (C) 2007, by it-raum.ch
 * martin.imobersteg@it-raum.ch
 *
 * It is free software; you can redistribute it and/or modify it under the terms of either:
 * a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or
 * b) the "Artistic License".
 */

#include "ui_settings.h"
#include "SettingsDialog.h"

#include <QtGui>

SettingsDialog::SettingsDialog(QWidget *parent) : QWidget(parent)
{
	setupUi(this);
	setWindowTitle(tr("Reflexis - Settings"));

	loadSettings();

	connect(m_okButton, SIGNAL(clicked()), this, SLOT(saveSettings()));
}

void SettingsDialog::closeEvent(QCloseEvent *event)
{
	event->ignore();
}

void SettingsDialog::saveSettings()
{
	qDebug("save settings");

	QSettings settings;
	settings.setValue("hostname", m_hostEdit->text());
	settings.setValue("database", m_dbEdit->text());
	settings.setValue("username", m_userEdit->text());
	settings.setValue("password", m_pwEdit->text());

	hide();
}

void SettingsDialog::loadSettings()
{
	qDebug("load settings");

	QSettings settings;
	m_hostEdit->setText(settings.value("hostname").toString());
	m_dbEdit->setText(settings.value("database").toString());
	m_userEdit->setText(settings.value("username").toString());
	m_pwEdit->setText(settings.value("password").toString());
}
